FROM rust:1.74 as builder
WORKDIR /app

# RUN mkdir /root/.cargo \
#  && echo 'registry = "https://github.com/rust-lang/crates.io-index"' > /root/.cargo/config \
#  && echo 'replace-with = "ustc"' >> /root/.cargo/config \
#  && echo '[source.ustc]' >> /root/.cargo/config \
#  && echo 'registry = "git://mirrors.ustc.edu.cn/crates.io-index"' >> /root/.cargo/config 

RUN rustup target add wasm32-unknown-unknown

RUN cargo install trunk

COPY ./Cargo.toml ./Cargo.lock ./index.html ./index.scss ./
COPY ./src ./src

RUN trunk build --release --public-url /todo --dist ./bin

FROM nginx:stable-alpine as nginx  
  
# 复制 Nginx 配置文件到镜像中（如果需要自定义配置）  
# COPY ./nginx.conf /etc/nginx/nginx.conf  
  
# 复制构建好的 Rust 应用到 Nginx 的默认网站目录  
WORKDIR /usr/share/nginx/html/todo/  
COPY --from=builder /app/bin/ ./
  
# 暴露 Nginx 的默认端口  
EXPOSE 80  
  
# 启动 Nginx 服务  
CMD ["nginx", "-g", "daemon off;"]
